package com.xiaomuwu.android.ui.login

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.ViewModel
import com.xiaomuwu.android.logic.Repository
import com.xiaomuwu.android.logic.model.ForCheckLogin
import com.xiaomuwu.android.logic.model.ForOperateUser

class LoginViewModel:ViewModel() {

    private val toLoginResult=MutableLiveData<ForCheckLogin>()

    private val toRegisterResult=MutableLiveData<ForOperateUser>()

    var loginResultLiveData=Transformations.switchMap(toLoginResult) { forCheckLogin ->
        Repository.checkLogin(forCheckLogin)
    }

    var  registerResultLiveData=Transformations.switchMap(toRegisterResult){forRegister->
        Repository.registerUser(forRegister)
    }

    fun getLoginResultLiveData(forCheckLogin: ForCheckLogin){
        toLoginResult.value=forCheckLogin
    }

    fun getRegisterResultLiveData(forOperateUser: ForOperateUser){
        toRegisterResult.value=forOperateUser
    }

}